package com.geostar.gmp.thread;

import java.util.concurrent.Callable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 文件名:AbstractJob.java
 * 功能: 
 * 目前支持方法
 * --------------------------------------
 * 初始版本 
 * 作者: yesong
 * 时间: Apr 10, 2014
 */
public abstract class AbstractJob implements Callable<Object>{

	private static Logger logger = LoggerFactory.getLogger(AbstractJob.class);
	private Lock lock;
	
	void setLock(Lock lock){
		this.lock = lock;
	}
	
	@Override
	public Object call() throws Exception {
		Object result = null;
		try{
			result = this.execute();
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(">>>>>>>>>>>>>>Job执行异常<<<<<<<<<<<<<<");
		}
		synchronized (lock) {
			lock.thread_num--;
			lock.notifyAll();
		}
		
		return result;
	}

	public abstract Object execute();
}

	class Lock{
		int thread_num;
	}
